<?php

class UploadAction extends Action {

    /**
     * 
     * 取得文件上传对象实例
     * @access protected
     */
    protected function _uploadImage() {
        import("@.ORG.Net.UploadFile");
        $upload = new UploadFile(); //实例化上传类
        $upload->maxSize = 3145728; //设置附件上传大小
        $upload->saveRule = uploadName; //附件上传规则
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->savePath = C('UPLOAD_PATH_PRODUCT'); // 设置附件上传目录
        return $upload;
    }
    /**
     * 上傳產品
     */
    public function uploadProduct() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    /**
     * 上傳廣告
     */
    public function uploadAdvert() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_ADVERT'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    
    /**
     * 上傳新聞
     */
    public function uploadNews() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_NEWS'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    
    /**
     * 上傳文章圖片
     */
    public function uploadArticle() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_ARTICLE'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    
    /**
     * 上傳推廣圖片
     */
    public function uploadPromote() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_PROMOTE'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    
    /**
     * 上傳推廣圖片
     */
    public function uploadImage() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_IMAGE'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
    
    /**
     * 上傳分類圖片
     */
    public function uploadCategory() {
        $upload = $this->_uploadImage();
        import("@.ORG.Util.Image");
        $upload->maxSize = 31457280; //设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->thumb = true;
        $upload->thumbMaxWidth = '200,800';
        $upload->thumbMaxHeight = '200,800';
        $upload->savePath = C('UPLOAD_PATH_CATEGORY'); // 设置附件上传目录
        if (!$upload->upload()) {
            debug($upload->getErrorMsg());
            $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
        } else {
            $info = $upload->getUploadFileInfo();
            $this->ajaxReturn(1, $info[0]['savename'], 1);
        }
    }
}
